package com.doit.day07

object _01_高阶函数 {

  def main(args: Array[String]): Unit = {
    val myFun: String => Int = (a:String)=>{a.toInt}
    //函数当做参数去传递
    val function: (Int, Int) => Int = funTest6("3", myFun)

    val res: Int = function(1, 2)
    println(res)




  }

  /*
   * funTest6:方法名称
   * (str:String,fun:(String)=>Int) ：参数str       fun:(String)=>Int
   * 还可以作为返回值返回
   * :(Int,Int)=>Int   funTest6 返回值类型
   */

  def funTest6(str:String,fun:(String)=>Int):(Int,Int)=>Int = {
    val i: Int = fun(str)
    /**
     * 模式匹配中的值匹配
     */
    i match {
      case 0 => (a,b)=>a+b
      case 1 => (a,b)=>a-b
      case 2 => (a,b)=>a*b
      case 3 => (a,b)=>a/b
    }
  }
}
